<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script src="js/jquery-3.3.1.js"></script>
<script>
  $(function () {
    let zq=[];

    $.getJSON("heroes_simple_cn.json",function (data) {
      let heroes=data.result.heroes;
      $.each(heroes,function (index,hero) {
        let dota2={};
        let d1={
          "id":btoa(hero.name),
          "name":hero.localized_name,
          "npc":hero.name,
          "dota2":dota2
        }
        zq.push(d1);
      })
    });
    setTimeout(function () {
      $.getJSON("111.json",function (data) {
        $.each(data,function (index,chatRes) {
          if(chatRes.code===undefined){
            let _c=chatRes.choices[0].message.content;
            let dota2_c=JSON.parse(_c);
            let dota2_gif_name=dota2_c.url.substr(dota2_c.url.lastIndexOf("/")+1);
            let dota2_name=dota2_gif_name.substr(0,dota2_gif_name.lastIndexOf("."));
            $.each(zq,function (index_zq,data_zq){
              if(data_zq.npc==dota2_name){
                data_zq.dota2.description1=dota2_c.description;
                data_zq.dota2.url=dota2_c.url;
                data_zq.dota2.score1=dota2_c.score;
                return;
              }
            })
          }else{

          }
        })
      })
      $.getJSON("222.json",function (data) {
        $.each(data,function (index,chatRes) {
          if(chatRes.code===undefined){
            let _c=chatRes.choices[0].message.content;
            let dota2_c=JSON.parse(_c);
            let dota2_gif_name=dota2_c.url.substr(dota2_c.url.lastIndexOf("/")+1);
            let dota2_name=dota2_gif_name.substr(0,dota2_gif_name.lastIndexOf("."));
            $.each(zq,function (index_zq,data_zq){
              if(data_zq.npc==dota2_name){
                data_zq.dota2.description2=dota2_c.description;
                data_zq.dota2.url=dota2_c.url;
                data_zq.dota2.score2=dota2_c.score;
                return;
              }
            })
          }else{

          }
        })
      })
      $.getJSON("333.json",function (data) {
        $.each(data,function (index,chatRes) {
          if(chatRes.code===undefined){
            let _c=chatRes.choices[0].message.content;
            let dota2_c=JSON.parse(_c);
            let dota2_gif_name=dota2_c.url.substr(dota2_c.url.lastIndexOf("/")+1);
            let dota2_name=dota2_gif_name.substr(0,dota2_gif_name.lastIndexOf("."));
            $.each(zq,function (index_zq,data_zq){
              if(data_zq.npc==dota2_name){
                data_zq.dota2.description3=dota2_c.description;
                data_zq.dota2.url=dota2_c.url;
                data_zq.dota2.score3=dota2_c.score;
                return;
              }
            })
          }else{

          }
        })
      })
        $.getJSON("444.json",function (data) {
            $.each(data,function (index,chatRes) {
                if(chatRes.code===undefined){
                    let _c=chatRes.choices[0].message.content;
                    let dota2_c=JSON.parse(_c);
                    let dota2_gif_name=dota2_c.url.substr(dota2_c.url.lastIndexOf("/")+1);
                    let dota2_name=dota2_gif_name.substr(0,dota2_gif_name.lastIndexOf("."));
                    $.each(zq,function (index_zq,data_zq){
                        if(data_zq.npc==dota2_name){
                            data_zq.dota2.description4=dota2_c.description;
                            data_zq.dota2.url=dota2_c.url;
                            data_zq.dota2.score4=dota2_c.score;
                            return;
                        }
                    })
                }else{

                }
            })
        })
        $.getJSON("555.json",function (data) {
            $.each(data,function (index,chatRes) {
                if(chatRes.code===undefined){
                    let _c=chatRes.choices[0].message.content;
                    let dota2_c=JSON.parse(_c);
                    let dota2_gif_name=dota2_c.url.substr(dota2_c.url.lastIndexOf("/")+1);
                    let dota2_name=dota2_gif_name.substr(0,dota2_gif_name.lastIndexOf("."));
                    $.each(zq,function (index_zq,data_zq){
                        if(data_zq.npc==dota2_name){
                            data_zq.dota2.description5=dota2_c.description;
                            data_zq.dota2.url=dota2_c.url;
                            data_zq.dota2.score5=dota2_c.score;
                            return;
                        }
                    })
                }else{

                }
            })
        })

        window.setTimeout(function () {
            $.each(zq,function (index,element) {
                element.score=((parseInt(element.dota2.score1===undefined?0:element.dota2.score1)*0.5
                    +parseInt(element.dota2.score2===undefined?0:element.dota2.score2)*10
                    +parseInt(element.dota2.score3===undefined?0:element.dota2.score3)*15
                    +parseInt(element.dota2.score4===undefined?0:element.dota2.score4)*20
                    +parseInt(element.dota2.score5===undefined?0:element.dota2.score5)*5)/25)*2+30;
            })
            zq.sort(function (a, b) {
                return a.score - b.score;
            });
            console.log(zq);
        },1000)
    },1000)
  })
</script>
</html>